home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
System Booster
/
System Booster.iso
/
Archives
/
ForCLI
/
Strings.lha
/
strings.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-12-03
|
3KB
|
140 lines
;/* Execute me to compile
SC IGNORE=73 NOSTACKCHECK SMALLCODE SMALLDATA STARTUP=cres NODEBUG OPTIMIZE LINK Strings.c
Quit
* Program: strings.c
* Author: Osma Ahvenlampi
* Description: search for ASCII strings in files
*/
#include <exec/types.h>
#include <dos/rdargs.h>
#include <dos/dos.h>
#include <dos/dosasl.h>
#include <proto/exec.h>
#include <proto/dos.h>
#define TEMPLATE "FILE/M,MINSIZE/K/N,MAXSIZE/K/N,LATIN1/S"
#define ARGNUM 5
#define MAXSTRING 256
#define MINSTRING 6
char VersionID[] = "$VER: Strings 1.2 (3.12.94)";
char ctable[] =
{
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
LONG ArgArray[ARGNUM];
ULONG minsize, maxsize, mask;
STRPTR buf;
void String( BPTR );
int __main( void )
{
STRPTR *files;
int rc = RETURN_OK;
struct RDArgs *RDArgs = ReadArgs( TEMPLATE, ArgArray, NULL );
minsize = ArgArray[1] ? *(ULONG *)ArgArray[1] : MINSTRING;
maxsize = ArgArray[2] ? *(ULONG *)ArgArray[2] : MAXSTRING;
mask = ArgArray[3] ? 0x7f : 0xff;
if ( maxsize < minsize )
{
PrintFault( ERROR_BAD_NUMBER, "Strings" );
rc = RETURN_FAIL;
}
else
{
if ( buf = (char *)AllocMem( maxsize + 2, 0 ) )
{
if (files = (char **)ArgArray[0])
{
STRPTR filename;
while ( filename = *(files++) )
{
BPTR in;
if (in = Open( filename, MODE_OLDFILE ))
{
String( in );
Close( in );
if ( SetSignal( 0L, 0L ) & SIGBREAKF_CTRL_C )
break;
}
else
{
PrintFault( IoErr(), "Strings" );
rc = RETURN_WARN;
break;
}
}
}
else
{
String( Input() );
}
FreeMem( buf, maxsize + 2 );
}
else
{
PrintFault( IoErr(), "Strings" );
rc = RETURN_FAIL;
}
}
if ( SetSignal( 0L, 0L ) & SIGBREAKF_CTRL_C )
{
PrintFault( ERROR_BREAK, NULL );
rc = RETURN_ERROR;
}
FreeArgs( RDArgs );
return rc;
}
void String( BPTR fh )
{
LONG c;
STRPTR i = buf;
while ( !(SetSignal(0L, 0L) & SIGBREAKF_CTRL_C) && ((c = FGetC( fh )) != -1) )
{
if (ctable[c & mask])
{
*(i++) = c;
if ( (i - buf) > maxsize )
{
*(i++) = '\n'; *i = 0;
PutStr( buf );
i = buf;
}
}
else
{
if ( (i - buf) >= minsize )
{
*(i++) = '\n'; *i = 0;
PutStr( buf );
}
i = buf;
}
}
}